<include file="public@header" />
<style>
	html {background-color: #ffffff;}.expander{margin-left: -20px;}.layui-table[lay-skin="nob"] td{border: none;}
	.layui-unselect{
		margin-top: 0px !important;
	}

</style>
</head>
<body>
<div class="js-check-wrap">
	<form class="layui-form js-ajax-form"  action="{:url('rbac/authorizePost')}" method="post" style="">
		<div class="layui-form-item">
			<table class="layui-table" lay-size="sm" lay-even id="authrule-tree">
				<tbody>{$category}</tbody>
			</table>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<input type="hidden" name="roleId" value="{$roleId}" />
				<button class="layui-btn js-ajax-submit js-close" id="js-ajax-submit" type="submit">{:lang('SAVE')}</button>
			</div>
		</div>
	</form>
</div>
<include file="public@script"/>
<script type="text/javascript">
    $(document).ready(function () {
        Wind.css('treeTable');
        Wind.use('treeTable', function () {
            $("#authrule-tree").treeTable({
                indent: 20
            });
        });
    });

    function checknode(obj) {
        var chk = $("input[type='checkbox']");
        var count = chk.length;

        var num = chk.index(obj);
        var level_top = level_bottom = chk.eq(num).attr('level');
        for (var i = num; i >= 0; i--) {
            var le = chk.eq(i).attr('level');
            if (le <level_top) {
                chk.eq(i).prop("checked", true);
                var level_top = level_top - 1;
            }
        }
        for (var j = num + 1; j < count; j++) {
            var le = chk.eq(j).attr('level');
            if (chk.eq(num).prop("checked")) {

                if (le > level_bottom){
                    chk.eq(j).prop("checked", true);
                }
                else if (le == level_bottom){
                    break;
                }
            } else {
                if (le >level_bottom){
                    chk.eq(j).prop("checked", false);
                }else if(le == level_bottom){
                    break;
                }
            }
        }
    }
	(function (){
		layui.use(['layer', 'jquery', 'form'], function () {
			var layer = layui.layer,
					$ = layui.jquery,
					form = layui.form;

			form.on('checkbox(switchTest)', function(data){
				let _that=$(this);
				checknode(_that);
				form.render();
			});

		});
	})()
</script>
</body>
</html>